#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#pragma unmanaged 
#include <ql\termstructures\volatility\abcd.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

#undef HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Termstructures { namespace Volatility {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IAbcdFunction
	public ref class CAbcdFunction  : 
            public Cephei::QL::Termstructures::Volatility::IAbcdFunction
	{
	protected: 
		boost::shared_ptr<QuantLib::AbcdFunction>* _ppAbcdFunction;
        boost::detail::spinlock* _pSpinlock;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::AbcdFunction>* _phAbcdFunction;
#endif
		Object^ _AbcdFunctionOwner;     // reference to object that manages the storage for this object
	internal:
		CAbcdFunction (Microsoft::FSharp::Core::FSharpOption<Double>^ a, Microsoft::FSharp::Core::FSharpOption<Double>^ b, Microsoft::FSharp::Core::FSharpOption<Double>^ c, Microsoft::FSharp::Core::FSharpOption<Double>^ d);
        CAbcdFunction (boost::shared_ptr<QuantLib::AbcdFunction>& childNative, Object^ owner);
        CAbcdFunction (QuantLib::AbcdFunction& childNative, Object^ owner);
        CAbcdFunction (CAbcdFunction^ copy);
        CAbcdFunction (PLATFORM::Type^ t);
#ifdef STRUCT
        CAbcdFunction (QuantLib::AbcdFunction childNative);
#endif       
#ifdef HANDLE
		CAbcdFunction (QuantLib::Handle<QuantLib::AbcdFunction>& childNative, Object^ owner);
		CAbcdFunction (QuantLib::Handle<QuantLib::AbcdFunction> childNative);
#endif
		virtual ~CAbcdFunction ();
		!CAbcdFunction ();

	internal:
		QuantLib::AbcdFunction& GetReference ();
		boost::shared_ptr<QuantLib::AbcdFunction>& GetShared ();
		QuantLib::AbcdFunction* GetPointer ();
        void SetAbcdFunction (boost::shared_ptr<QuantLib::AbcdFunction> native)
        {
            if (_ppAbcdFunction != NULL)
                delete _ppAbcdFunction;
            _ppAbcdFunction = new boost::shared_ptr<QuantLib::AbcdFunction> (native);
            
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::AbcdFunction>& GetHandle ();
#endif
		virtual bool HasNative () ;
		void Lock ()
		{
			if (Cephei::QL::Settings::_ReferenceLocking)
    			_pSpinlock->lock ();
		}
		void Unlock ()
		{
			_pSpinlock->unlock ();
		}
    public:
        property Double A 
        {
		    virtual Double get () ;
        }
        property Double B 
        {
		    virtual Double get () ;
        }
        property Double C 
        {
		    virtual Double get () ;
        }
		virtual Double Covariance (Double t1, Double t2, Double T, Double S) ;
		virtual Double Covariance (Double t, Double T2, Double S) ;
        property Double D 
        {
		    virtual Double get () ;
        }
		virtual Double InstantaneousCovariance (Double u, Double T, Double S) ;
		virtual Double InstantaneousVariance (Double t, Double T2) ;
		virtual Double InstantaneousVolatility (Double t, Double T2) ;
        property Double LongTermVolatility 
        {
		    virtual Double get () ;
        }
        property Double MaximumLocation 
        {
		    virtual Double get () ;
        }
        property Double MaximumVolatility 
        {
		    virtual Double get () ;
        }
		virtual Double Primitive (Double t, Double T2, Double S) ;
        property Double ShortTermVolatility 
        {
		    virtual Double get () ;
        }
		virtual Double Variance (Double tMin, Double tMax, Double T) ;
		virtual Double Volatility (Double tMin, Double tMax, Double T) ;
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Termstructures::Volatility::IAbcdFunction^>::typeid)]
	[FactoryFor(Cephei::QL::Termstructures::Volatility::IAbcdFunction::typeid)]
	[FactoryFor(Cephei::QL::Termstructures::Volatility::IAbcdFunction_Factory::typeid)]
	public ref class CAbcdFunction_Factory sealed : public IAbcdFunction_Factory
	{
	public:
        virtual IAbcdFunction^ Create (Microsoft::FSharp::Core::FSharpOption<Double>^ a, Microsoft::FSharp::Core::FSharpOption<Double>^ b, Microsoft::FSharp::Core::FSharpOption<Double>^ c, Microsoft::FSharp::Core::FSharpOption<Double>^ d);
    };
   
/*Cephei*/ } /*QL*/ } /*Termstructures*/ } /*Volatility */}
